package com.longsys.eventsourcing.demo.eventsourcing.repository;

import com.longsys.eventsourcing.demo.eventsourcing.domain.UserAggr;
import com.longsys.eventsourcing.demo.mapper.UserMapper;
import com.longsys.eventsourcing.demo.mapper.UserRoleMapper;
import com.longsys.eventsourcing.demo.model.User;
import com.longsys.framework.eventsourcing.sbclient.core.AggregateRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserAggrRepository implements AggregateRepository<UserAggr> {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserRoleMapper userRoleMapper;

    public UserAggr findById(Object id) {
        int userId = Integer.parseInt(String.valueOf(id));
        User user = userMapper.selectById(userId);

        UserAggr userAggr = new UserAggr();
        userAggr.setId(userId);
        userAggr.setName(user.getName());
        return userAggr;
    }
}
